Neural network computation method using adaptive data representation

ABSTRACT

A method for neural network computation using adaptive data representation, adapted for a processor to perform multiply-and-accumulate operations on a memory having a crossbar architecture, is provided. The memory comprises multiple input and output lines crossing each other, multiple cells respectively disposed at intersections of the input and output lines, and multiple sense amplifiers respectively connected to the output lines. In the method, an input cycle of kth bits respectively in an input data is adaptively divided into multiple sub-cycles, wherein a number of the divided sub-cycles is determined according to a value of k. The kth bits of the input data are inputted to the input lines with the sub-cycles and computation results of the output lines are sensed by the sense amplifiers. The computation results sensed in each sub-cycle are combined to obtain the output data corresponding to the kth bits of the input data.

CROSS-REFERENCE TO RELATED APPLICATION

This application is a divisional application of and claims the prioritybenefit of U.S. application Ser. No. 16/798,166, filed on Feb. 21, 2020.The prior U.S. application Ser. No. 16/798,166 claims the prioritybenefits of U.S. provisional application Ser. No. 62/823,670, filed onMar. 26, 2019. The entirety of each of the above-mentioned patentapplications is hereby incorporated by reference herein and made a partof this specification.

BACKGROUND Field of the Disclosure

The present disclosure relates to neural network computations, and moreparticularly to a method for neural network computation using adaptivedata representation.

Description of Related Art

Deep neuron networks (DNNs), compared with traditional machine learningapproaches, have shown its capability to achieve higher accuracy onseveral domains such as image recognition and speech recognition.However, several challenges have emerged on performing DNN over thecurrent Von-Neumann architecture. For example, the excessive datamovement between processing units and off-chip memory units onperforming DNN incurs the performance limitation and high powerconsumption.

To bridge the gap between computing and memory units, the concept ofProcessing-In-Memory (PIM) is widely advocated, and the crossbaraccelerators with Resistive Random-Access Memory (ReRAM) are one of themost intensively-studied solutions. ReRAM, one of emerging non-volatilememories (NVMs), memorizes data by changing the resistance of cells andare proved to possess both capabilities of computing and memorizing.Specifically, crossbar accelerators perform digital DNN operations,i.e., Multiply-and-Accumulate (MAC) operations, on the analog aspect bysetting different input voltages and resistance values to representinput and weight values, respectively.

For example, FIG. 1 shows an example of performing the computation ofMAC operations by using a crossbar accelerator, and this example aims tocalculate the result of Σ(V_(n)×G_(n)). In this example, each wordlineis connected to each bitline by a ReRAM cell at the cross point in the3D space. By Kirchhoff's current law (KCL), given voltages V1 and V2 tothe corresponding wordlines, the emerged electric currents I1, I2, I3,I4 of each ReRAM cell induced by conductance G1, G2, G3, G4 areaccumulated to currents I5 and I6 on the corresponding bitlinesinstantaneously. The results of the MAC operations are retrievedsimultaneously by sensing currents on each bitline, where the value ofI5 equals to V1×G1+V2×G2 and the value of I6 equals to V1×G3+V2×G4.

However, in practice, it is hard to program the resistance values ofeach ReRAM cell to represent arbitrary weight values, and thus, thisprogramming variation issue leads to analog variation errors whileconverting the result from analog to digital aspects.

SUMMARY

In view of the above, the present disclosure provides a method and anapparatus for neural network computation using adaptive datarepresentation capable of reducing the resistance converting distortionand increasing the accuracy of neural network computation.

The present disclosure provides a neural network computation methodusing adaptive data representation, adapted for a processor to performmultiply-and-accumulate (MAC) operations on a memory having a crossbararchitecture. The memory comprises a plurality of input lines and aplurality of output lines crossing each other, a plurality of cellsrespectively disposed at intersections of the input lines and the outputlines, and a plurality of sense amplifiers respectively connected to theoutput lines. In the method, an input cycle of kth bits respectively ina plurality of input data to be inputted to the input lines isadaptively divided into a plurality of sub-cycles, wherein a number ofthe divided sub-cycles is determined according to a value of k and k isan integer. The kth bits of the plurality of input data are inputted tothe input lines with the sub-cycles and computation results of theoutput lines are sensed by the sense amplifiers. The computation resultssensed in each sub-cycle are combined to obtain a plurality of outputdata corresponding to the kth bits of the input data.

In an embodiment of the disclosure, the output data corresponding to thebits of each order of the input data is multiplied with correspondingexponential base and multiplication results of the bits of all ordersare summed to obtain a final output data.

In an embodiment of the disclosure, the number of the divided sub-cyclesincreases as the value of k increases and a maximum number of the inputlines involved in each of the divided sub-cycles is determined accordingto a resolution of the sense amplifiers.

In an embodiment of the disclosure, the input lines are wordlines of thememory and the output lines are bitlines of the memory, or the inputlines are bitlines of the memory and the output lines are wordlines ofthe memory.

The present disclosure provides a neural network computation methodusing adaptive data representation, adapted for a processor to performmultiply-and-accumulate (MAC) operations on a memory having a crossbararchitecture. The memory comprises a plurality of input lines and aplurality of output lines crossing each other, a plurality of cellsrespectively disposed at intersections of the input lines and the outputlines, and a plurality of sense amplifiers respectively connected to theoutput lines. In the method, a plurality of weight values to berespectively programmed into the cells are retrieved. A number of bitsrepresenting a low resistance state (LRS) in a binary representation ofa target weight value among the weight values is counted. A plurality ofcandidate weight values around the target weight value are inquired tofind one of the candidate weight values having a number of bitsrepresenting the LRS in a binary representation less than the countednumber of bits by at least a rounding threshold. The found candidateweight value in replacement of the target weight value is programmed tothe corresponding cell.

In an embodiment of the disclosure, the target weight value to thecorresponding cell is programmed if no candidate weight value is found.

In an embodiment of the disclosure, in the step of inquiring a pluralityof candidate weight values around the target weight value, a pluralityof weight values having a difference from the target weight value lessthan or equal to a rounding distance are inquired as the candidateweight values.

The present disclosure provides a neural network computation apparatususing adaptive data representation comprises a memory and a processor.The memory comprises a plurality of input lines and a plurality ofoutput lines crossing each other, a plurality of cells respectivelydisposed at intersections of the input lines and the output lines, and aplurality of sense amplifiers respectively connected to the outputlines. The processor is coupled to the memory and configured to performMAC operations comprising steps of: adaptively dividing an input cycleof kth bits respectively in a plurality of input data to be inputted tothe input lines into a plurality of sub-cycles, wherein a number of thedivided sub-cycles is determined according to a value of k and k is aninteger; inputting the kth bits of the plurality of input data to theinput lines with the sub-cycles and sensing computation results of theoutput lines by the sense amplifiers; and combining the computationresults sensed in each sub-cycle to obtain a plurality of output datacorresponding to the kth bits of the input data.

In an embodiment of the disclosure, the processor multiplies the outputdata corresponding to the bits of each order of the input data withcorresponding exponential base and sums multiplication results of thebits of all orders to obtain a final output data.

In an embodiment of the disclosure, the processor increases the numberof the divided sub-cycles as the value of k increases and determines amaximum number of the input lines involved in each of the dividedsub-cycles according to a resolution of the sense amplifiers.

In an embodiment of the disclosure, the processor further comprises:retrieving a plurality of weight values to be respectively programmedinto the cells; counting a number of bits representing a low resistancestate (LRS) in a binary representation of a target weight value amongthe weight values; inquiring a plurality of candidate weight valuesaround the target weight value to find one of the candidate weightvalues having a number of bits representing the LRS in a binaryrepresentation less than the counted number of bits by at least arounding threshold; and programming the found candidate weight value inreplacement of the target weight value to the corresponding cell.

In an embodiment of the disclosure, the processor comprises programmingthe target weight value to the corresponding cell if no candidate weightvalue is found.

In an embodiment of the disclosure, the processor comprises inquiring aplurality of weight values having a difference from the target weightvalue less than or equal to a rounding distance as the candidate weightvalues.

In an embodiment of the disclosure, a number of the divided sub-cyclesfor most significant bits (MSBs) in the input data is larger than anumber of the divided sub-cycles for least significant bits (LSBs) inthe input data.

In an embodiment of the disclosure, the memory comprises NAND flash, NORflash, phase change memory (PCM), spin-transfer torque random-accessmemory (STT-RAM), or resistive random-access memory (ReRAM) of 2D or 3Dstructure.

In order to make the aforementioned features and advantages of thedisclosure more comprehensible, embodiments accompanying figures aredescribed in detail below.

BRIEF DESCRIPTION OF THE DRAWINGS

FIG. 1 shows an example of performing the computation of MAC operationsby using a crossbar accelerator.

FIG. 2A shows the distribution of the output current for all ReRAM cellsby applying an identical voltage to program all cells in a ReRAM chip tothe low resistance state (LRS) and high resistance state (HRS).

FIG. 2B to FIG. 2D illustrate the challenge of a crossbar accelerator onconverting the accumulated currents, especially when more validwordlines are involved.

FIG. 3 is a schematic diagram of a neural network computation apparatususing adaptive data representation according to an embodiment of thedisclosure.

FIG. 4 is a flow chart of neural network computation method usingadaptive data representation according to an embodiment of thedisclosure.

FIG. 5A shows an example of performing MAC operations on inputs andweights represented by 3-bit values through the crossbar accelerator.

FIG. 5B shows an example of performing MAC operations inputs and weightsrepresented by 4-bit values with sub-cycles through the crossbaraccelerator according to an embodiment of the disclosure.

FIG. 6 is a flow chart of neural network computation method usingadaptive data representation according to an embodiment of thedisclosure.

FIG. 7A and FIG. 7B are examples illustrating the weight rounding policy(WRP) according to an embodiment of the disclosure.

DESCRIPTION OF EMBODIMENTS

Due to the resistance programming variation, the accumulated currentsinduced by MAC operations for different values are probably converted tothe same value. Thus, the crossbar accelerator suffers from theoverlapping variation error while it converts the accumulated currentsto a digital output in each MAC operation. The overlapping variationerror is that some accumulated currents are converted to an incorrectdigital value during the analog to digital conversion step, because morethan one possible digital values are mapped to the same accumulatedcurrent. It is noted that the magnitude of the accumulated current isonly influenced by input lines supplied with input voltage. Thus, “validinput line” is defined as the input lines with input voltage during aMAC operation.

FIG. 2A shows the distribution of the output current for all ReRAM cellsby applying an identical voltage to program all cells in a ReRAM chip tothe low resistance state (LRS) and high resistance state (HRS). When apredefined voltage (e.g., 0.3 V) is applied to the input lines whosecorresponding input bit values are “1”, the possible distribution of theoutput current for all ReRAM cells is as shown in FIG. 2A. The x-axis ofFIG. 2A denotes the current and the y-axis denotes the frequency.

FIG. 2B to FIG. 2D illustrate the challenge of a crossbar accelerator onconverting the accumulated currents, especially when more valid inputlines are involved. FIG. 2B illustrates four possible cases incurred bythree valid input lines and their corresponding digital values. Thex-axis of FIG. 2B denotes the current and the y-axis denotes thefrequency. These four cases (i.e., 3I_(HRS), 2 I_(HRS)+1I_(LRS), 1IHRS+2I_(HRS) and 3I_(LRS)) may induce accumulated current within four ranges(i.e., 0.00-0.01 mA, 0.01-0.02 mA, 0.02-0.35 mA, and 0.034-0.05 mA), andwill be converted into four digital outputs (i.e., 0, 1, 2 and 3),respectively. It is noted that, the overlapping variation error occurswhen the accumulated current is, for example, around 0.034 mA and willbe ambiguously converted to digital value either 2 or 3.

The probability of the overlapping variation error becomes higher whenmore valid input lines are involved in the MAC operation. FIG. 2C showsthe probability of the overlapping variation error of 10 valid inputlines while FIG. 2D shows the probability of the overlapping variationerror of 20 valid input lines. It is noted that the probability of theoverlapping variation error grows dramatically as more valid input linesare involved.

In the embodiment of the present disclosure, an adaptive datarepresentation strategy is proposed to transform both inputs and weightswith exploiting the property of data representation, so as tosignificantly reduce the occurrence of the overlapping variation error.Besides, the transformation is an offline strategy without incurring anyruntime overhead. The proposed strategy includes two policies, i.e.,Adaptive Input Sub-cycling Policy (AISP) and Weight Rounding Policy(WRP), where AISP focuses on the data representation of inputs and WRPfocuses on the data representation of model weights.

AISP trades the accuracy and performance in different input cycles to(1) minimize the overlapping variation error on the cycles for the mostsignificant bits (MSBs) and (2) boost the performance during the cyclesfor the least significant bits (LSBs).

WRP performs approximate transformation on all weights in the givenneural network (NN) model and returns an approximating NN model with lowoverlapping variation errors. It is noted that both policies aredesigned to decrease the occurrence/probability of the overlappingvariation error in different aspects (i.e., inputs and model weights)and can achieve better accuracy when they are applied together.

FIG. 3 is a schematic diagram of a neural network computation apparatususing adaptive data representation according to an embodiment of thedisclosure. Referring to FIG. 3 , the neural network computationapparatus 30 of the embodiment is, for example, a crossbar acceleratorfor neural network computation, and is configured to realizeprocess-in-memory (PIM) so as to eliminate the data movement betweencomputation and memory cells. The neural network computation apparatus30 comprises a memory 32 and a processor 34.

The memory 32 is, for example, NAND flash, NOR flash, phase changememory (PCM), spin-transfer torque random-access memory (STT-RAM), orresistive random-access memory (ReRAM) of 2D or 3D structure, which isnot limited herein. The memory 32 comprises a plurality of input linesIL_(i) and a plurality of output lines OL_(j) crossing each other, aplurality of cells (represented by its resistance R_(ij)) respectivelydisposed at intersections of the input lines IL_(i) and the output linesOL_(j), and a plurality of sense amplifiers SA respectively connected tothe output lines OL_(j). In some embodiments, the input lines IL_(i) arewordlines while the output lines OL_(j) are bitlines, and in someembodiments, the input lines IL_(i) are bitlines while the output linesOL_(j) are wordlines, which is not limited herein.

The processor 34 is, for example, a central processing unit (CPU), orother programmable general-purpose or specific-purpose microprocessor,microcontroller (MCU), programmable controller, application specificintegrated circuits (ASIC), programmable logic device (PLD) or othersimilar devices or a combination of these devices; the embodimentprovides no limitation thereto. In the present embodiment, the processor34 is configured to execute instructions for performing the neuralnetwork computation method as described below.

[Adaptive Input Sub-cycling Policy (AISP)]

Current crossbar accelerators perform an operation by setting voltageson all the wordlines (i.e., 128) simultaneously in one cycle. However,based on the experimental results as presented in FIG. 2(d), it incursunacceptable probability of the overlapping variation error whileperforming operations on merely 20 valid wordlines in a cycle. Thus, inthe present disclosure, it is proposed to divide an input cycle intoseveral sub-cycles, each of which is a basic computation unit, so thatthe overlapping variation error can be directly relieved.

For example, if an input cycle involves n wordlines and each sub-cycleinvolves m wordlines at a time, it needs at most n/m sub-cycles tocomplete this input cycle. As a value of m decreases, the probability ofthe overlapping variation error can be reduced but the total executiontime may be increased. Moreover, the magnitude of the overlappingvariation error incurred in different cycles has different impact on thefinal accuracy of the crossbar accelerators. Specifically, according tothe 2's complement data representation, the magnitude of the errorinduced by each input cycle, which implies the order of the exponentialpart, is magnified by the corresponding exponent power. Thus, themagnitude of the error induced by most significant bits (MSBs) isseverer than that induced by least significant bits (LSBs).

To be aware of the error magnification incurred by different inputcycles, in the present disclosure, a neural network computation methodis proposed to adaptively divide each input cycle according to thecorresponding bit orders/positions. That is, the ith input cycle will bedivided into sub-cycles with m_(i) wordlines. Since the cycles for MSBsare error sensitive but the cycles for LSBs are not sensitive, themethod minimizes the magnitude of error during the cycles for MSBs andboosting the performance during the cycles for LSBs. Specifically, forthe input cycles with respect to the bits located closer to the MSB,each of the divided sub-cycles involves fewer wordlines so as to reducethe probability of the overlapping variation error, and for the inputcycles with respect to the bits located closer to the LSB, each of thedivided sub-cycles involves greater wordlines so as to reduce the totalexecution time.

In detail, FIG. 4 is a flow chart of neural network computation methodusing adaptive data representation according to an embodiment of thedisclosure. Referring to FIG. 3 and FIG. 4 , the method of the presentembodiment is adaptable for the above-mentioned neural networkcomputation apparatus 30, and the detailed steps of the neural networkcomputation method of the present embodiment will be described belowwith reference to the various devices and components of the neuralnetwork computation apparatus 30.

First, in step S402, the processor 34 adaptively divides an input cycleof kth bits respectively in a plurality of input data to be inputted tothe input lines into a plurality of sub-cycles, wherein a number of thedivided sub-cycles is determined according to a value of k and k is aninteger. In one embodiment, the processor 34 increases the number of thedivided sub-cycles as the value of k increases and determines a maximumnumber of the input lines involved in each of the divided sub-cyclesaccording to a resolution of the sense amplifiers. That is, as the valueof k increases, the bits to be inputted are located closer to the MSBwhich means the bits are relatively significant bits, and thus, thenumber of the divided sub-cycles is increased to increase thecomputation accuracy. On the contrary, as the value of k decreases, thebits to be inputted are located closer to the LSB which means the bitsare less significant, and thus, the number of the divided sub-cycles isdecreased to save the computation time. Specifically, a number of thedivided sub-cycles for MSBs in the input data is larger than a number ofthe divided sub-cycles for LSBs in the input data. It is noted thenumber of states that can be recognized by the sense amplifiers islimited by the resolution of the sense amplifiers, and accordingly thenumber of the input lines involved in each of the divided sub-cycles isalso limited.

Then, in step S404, the processor 34 inputs the kth bits of theplurality of input data to the input lines with the sub-cycles andsenses computation results of the output lines by the sense amplifiersSA, and in step S406, the processor 34 combines the computation resultssensed in each sub-cycle to obtain a plurality of output datacorresponding to the kth bits of the input data.

It is noted that after obtaining the output data corresponding to thebits of each order of the input data, the processor 34 furthermultiplies the output data corresponding to the bits of each order ofthe input data with corresponding exponential part and sumsmultiplication results of the bits of all orders to obtain a finaloutput data.

FIG. 5A shows an example of performing MAC operations on inputs andweights represented by 3-bit values through the crossbar accelerator.The crossbar accelerator transforms values of the inputs [2, 3, −3, −4]and weights [−1, −3, 1, 2] into 3-bit signed fixed point values and thenfeeds the transformed input bits cycle by cycle. The result of the 1stcycle is (1×(−2²)+0×2¹+2×2⁰)×2⁰=−2, the 2nd cycle is(2×(−2²)+1×2¹+2×2⁰)×2¹=−8, and the 3rd cycle is(0×(−2²)+1×2¹+1×2⁰)×(−2²)=−12. After that, the crossbar acceleratormerges the output of all cycles to get the final result, that is,(−2)+(−8)+(−12)=−22.

FIG. 5B shows an example of performing MAC operations inputs and weightsrepresented by 4-bit values with sub-cycles through the crossbaraccelerator according to an embodiment of the disclosure. The crossbaraccelerator transforms values of the inputs [10, 3, 9, 1, . . . , 1] andweights [14, 10, 3, 8, . . . , 1] into 4-bit signed fixed point valuesand then feeds the transformed input bits. It is noted that, instead ofperforming the MAC operation on all the wordlines simultaneously in onecycle as exemplified in FIG. 5A, in FIG. 5B, an input cycle of the bitsof each order is divided into multiple sub-cycles according to the orderof the bits. For example, an input cycle of the 0^(th) bits (i.e. theLSB) is divided into 2 sub-cycles and a number of input lines involvedin each sub-cycle is n/2 where n represents a total number of the inputlines. An input cycle of the 1^(st) bits is divided into 4 sub-cyclesand a number of input lines involved in each sub-cycle is n/4. An inputcycle of the 2^(nd) bits is divided into 5 sub-cycles and a number ofinput lines involved in each sub-cycle is n/5. An input cycle of the3^(rd) bit (i.e. the MSB) is divided into 10 sub-cycles and a number ofinput lines involved in each sub-cycle is n/10. Accordingly, assumingthe total number n of the input lines is 20, the number of input linesinvolved in the computation of the 0^(th), 1^(st), 2^(nd), 3^(rd) bitsin each sub-cycle are 10, 5, 4 and 2, respectively. The result of eachcycle is multiplied with its exponential part (i.e., 2⁰, 2¹, 2² and 2³)to obtain a final computation result.

Through the method described above, the calculation time for the bits oflower order can be saved through fewer sub-cycles (e.g. 2 cycles for0^(th) bits) and the saved time can be used for the calculation of thebits of higher order through greater sub-cycles (e.g. 10 cycles for3^(rd) bits). Accordingly, the overlapping variation error can bereduced.

[Weight Rounding Policy (WRP)]

It is noted that the probability of the overlapping variation error isproportional to the number of the cells (e.g. ReRAM cells) programmed inthe low resistance state (LRS) in each sub-cycle, as show in FIG. 2A toFIG. 2D. The reason is that, according to Ohm's law, the current valueis inversely proportional to the resistance value under the same inputvoltage. Thus, compared with the high resistance state (HRS), possiblecurrent values induced by the cells in the LRS are greater and willcover a wider range. Thus, as shown in FIG. 2A to FIG. 2D, the currentdistribution becomes wider while more cells in the LRS are involved; andwider distribution overlaps with neighbor distributions, so that theoverlapping distribution increases the error rates for the analog todigital conversion.

For running DNN with crossbar accelerators, model weight values aredecomposed to a series of binary bits and each cell representing a bitvalue of “1” is programmed to the LRS. On the other hand, DNN is knownas an approximate computing technique. Its accuracy may not be affectedseriously when its weight values only have small deviations. Thus,slightly modifying model weight values may not seriously impact theoverall accuracy.

To relieve the overlapping distribution issue incurred by cells in theLRS, a Weight Rounding Policy (WRP) is proposed in the disclosure totransform the original weight values to their neighbor values with fewer1's. For example, the crossbar accelerator transforms a weight value of“255” represented by 0b011111111 in binary, to a weight value of “256”represented by 0b100000000 in binary, which has fewer 1's. In oneembodiment, a number of bits representing the LRS in a binaryrepresentation of each weight value is maximized to reduce theoverlapping variation error within limited impact on the model accuracy.

In detail, FIG. 6 is a flow chart of neural network computation methodusing adaptive data representation according to an embodiment of thedisclosure. Referring to FIG. 3 and FIG. 6 , the method of the presentembodiment is adaptable for the above-mentioned neural networkcomputation apparatus 30, and the detailed steps of the neural networkcomputation method of the present embodiment will be described belowwith reference to the various devices and components of the neuralnetwork computation apparatus 30.

First, in step S602, the processor 34 retrieves a plurality of weightvalues to be respectively programmed into the cells.

In step S604, the processor 34 counts a number of bits representing alow resistance state (LRS) in a binary representation of a target weightvalue among the weight values.

In step S606, the processor 34 inquires a plurality of candidate weightvalues around the target weight value to find one of the candidateweight values having a number of bits representing the LRS in a binaryrepresentation less than the counted number of bits by at least arounding threshold, in which the round threshold is set as, for example,an integer between 2 and 4, but the disclosure is not limited thereto.In one embodiment, the processor 34 may inquires a plurality of weightvalues having a difference from the target weight value less than orequal to a rounding distance as the candidate weight values.

In detail, in the present embodiment, two main parameters for finegrained tuning are provided. The parameters are rounding distance (K)and minimum rounding gain (G). The rounding distance implies the maximumrounding range for all weight values and the minimum rounding gainprovides a minimum bound to avoid weights to be rounded withinsufficient gain regarding the total number of cells in the LRS.

Assuming there are a predefined rounding distance K and a minimumrounding gain g, and given a weight value Ws, the processor 34 aims topick up a weight value Wt represented with the fewest number of 1's andsatisfied with two conditions as follows. It is noted that B_(LRS) is afunction to count the number of bits in the LRS after applying thebinary representation.|W _(s) −W _(t) |≤K  (1)B _(LRS)(W _(s))−B _(LRS)(W _(t))≥g  (2)

The recommended configuration selection is to pick up a larger K with aproper g under an acceptable model accuracy. That is because, accordingto condition (1), a larger K provides greater probability to performrounding for all weights so as to improve the efficiency for WRP. On theother hand, a proper g is to limit the degradation of model accuracy byreducing the total amount of weight rounding.

For example, FIG. 7A and FIG. 7B are examples illustrating the weightrounding policy (WRP) according to an embodiment of the disclosure.Referring to FIG. 7A, a weight value of “−1” represented by 111111111111in binary is rounded to a weight value of “0” represented by000000000000 in binary, which has fewer 1's. A weight value of “183”represented by 000010110111 in binary is rounded to a weight value of“184” represented by 000010111000 in binary, which has fewer 1's.Referring to FIG. 7B, for a given weight value Ws, a rounding distance Kis given to define a range around the weight value Ws for inquiring thecandidate weight values, and a threshold value T is given to determinewhether the candidate weight value being found can be used to re-writethe original weight value. In the present embodiment, the thresholdvalue T is set as 3 and therefore if a weight value Wt having a numberof bits “1” in a binary representation is less than the number of bitsof “1” of the weight value Ws by at least 3, the weight value Wt isselected to be programmed to the corresponding cell in replacement ofthe weight value Ws.

It is noted that the impact on model accuracy is unpredictable whilesetting different values of g with the same K. That is, the inferenceresult of DNN is decided by comparing all the values in a lowdimensional output vector generated by a series of high dimensionalmodel multiplications, and thus it is hard to predict the impact on thefinal output while applying the WRP with different configurations toeach model. Accordingly, an offline analysis may be used for each DNNmodel. That is, a proper configuration of both K and g for different DNNmodels can be tuned at the sever side beforehand; after that, DNN modelsare transformed by selecting configuration on the server before beingsent to the crossbar accelerator. It is noted that WRP can beimplemented by checking look-up tables, and the optimal transformationregarding the total number of LRS bits for each weight value underdifferent rounding distance and minimum rounding gain can be maintainedin a look-up table in the server.

That is, in one embodiment, a look-up table can be previouslyestablished through an offline analysis, in which the candidate weightvalue having a number of bits representing the LRS in a binaryrepresentation less than a number of bits of an arbitrary weight valueby at least a rounding threshold is recorded. As such, the processor 34may find the candidate weight value used for replacing the target weightvalue by looking up the look-up table.

Finally, in step S608, the processor 34 programs the found candidateweight value in replacement of the target weight value to thecorresponding cell, in which, if no candidate weight value is found, theprocessor 34 programs the target weight value to the corresponding cell.

Through the method described above, decreasing of overlapping variationerror can be maximized with limited impact on the model accuracy.

In summary, in the method and the apparatus for neural networkcomputation using adaptive data representation provided in theembodiments of the present disclosure, the inputs and weights used forneural network computation are transformed into binary representationwith exploiting the property of digital data such that the analogvariation error can be relieved. The method and the apparatus could alsobe applied to all systems that contain devices designed to run onresource-constrained devices like IOT devices to perform binaryconvolutional neural networks (BCNN), but the disclosure is not limitedthereto.

Although the disclosure has been disclosed by the above embodiments, theembodiments are not intended to limit the disclosure. It will beapparent to those skilled in the art that various modifications andvariations can be made to the structure of the disclosure withoutdeparting from the scope or spirit of the disclosure. Therefore, theprotecting range of the disclosure falls in the appended claims.

What is claimed is:
 1. A neural network computation method usingadaptive data representation, adapted for a processor to performmultiply-and-accumulate (MAC) operations on a memory having a crossbararchitecture, wherein the memory comprises a plurality of input linesand a plurality of output lines crossing each other, a plurality ofcells respectively disposed at intersections of the input lines and theoutput lines, and a plurality of sense amplifiers respectively connectedto the output lines, the method comprising: retrieving a plurality ofweight values to be respectively programmed into the cells; counting anumber of bits representing a low resistance state (LRS) in a binaryrepresentation of a target weight value among the weight values;inquiring a plurality of candidate weight values around the targetweight value to find one of the candidate weight values having a numberof bits representing the LRS in a binary representation less than thecounted number of bits by at least a rounding threshold; and programmingthe found candidate weight value in replacement of the target weightvalue to the corresponding cell.
 2. The method of claim 1, wherein thestep of programming the found candidate weight value in replacement ofthe target weight value to the corresponding cell comprises: programmingthe target weight value to the corresponding cell if no candidate weightvalue is found.
 3. The method of claim 1, wherein the step of inquiringa plurality of candidate weight values around the target weight valuecomprises: inquiring a plurality of weight values having a differencefrom the target weight value less than or equal to a rounding distanceas the candidate weight values.
 4. The method of claim 1, wherein thememory comprises NAND flash, NOR flash, PCM, STT-RAM, or ReRAM of 2D or3D structure.
 5. The method of claim 1, wherein the input lines arewordlines of the memory and the output lines are bitlines of the memory,or the input lines are bitlines of the memory and the output lines arewordlines of the memory.